FUNCTION YBC_SWS_CALLBACK_DP.
*"----------------------------------------------------------------------
*"*"本地接口：
*"  IMPORTING
*"     VALUE(IV_APPLEVEL) TYPE  YBC_SWS_APPROVER-APPLEVEL
*"     VALUE(IV_BUSINESSID) TYPE  YBC_SWS_REQUEST-BUSINESSID
*"     VALUE(IV_ACTION) TYPE  YBC_SWS_APPROVER-ACTION
*"     VALUE(IV_COMMENTS) TYPE  YBC_SWS_APPROVER-COMMENTS OPTIONAL
*"     VALUE(IV_SENDBACKLEVEL) TYPE  YBC_SWS_APPROVER-APPLEVEL OPTIONAL
*"     VALUE(IV_APPROVERID) TYPE  YBC_SWS_APPROVER-APPROVERID OPTIONAL
*"  EXPORTING
*"     VALUE(ES_MSG) TYPE  BAPIRET2
*"  TABLES
*"      ET_APPROVER_NEXT STRUCTURE  YBCS_SWS_APPROVER OPTIONAL
*"  CHANGING
*"     VALUE(CV_FINISHED) TYPE  CHAR1
*"----------------------------------------------------------------------
**********************************************************************
* 若审批人由SwiftSAP配置实现，请勿修改ET_APPROVER_NEXT及CV_FINISHED 内容
* 若审批人由外部函数提供：若是最后一级审批，需设置EV_FINISHED = 'X'
*                        若不是最后一级审批，需提供ET_APPROVER_NEXT
**********************************************************************
  DATA:
    LT_MSG     TYPE TABLE OF BAPIRET2 WITH HEADER LINE,
    LT_DP_LIST TYPE TABLE OF /OPT/DP_LIST WITH HEADER LINE.

  CLEAR:
    ES_MSG.

   "For DP need update DP approval history table

  CASE IV_ACTION.
    WHEN 'REJECT'.



    WHEN 'APPROVE'.
      IF CV_FINISHED IS NOT INITIAL. "最后一级审批DP过账
        SELECT SINGLE *
          INTO @DATA(LS_DP_HEADER)
          FROM /OPT/VIM_1HEAD
         WHERE DOCID = @IV_BUSINESSID.

        IF SY-SUBRC <> 0.
          ES_MSG-TYPE = 'E'.
          ES_MSG-MESSAGE = '未找到DP单据，请联系管理员'.
          RETURN.
        ENDIF.

        REFRESH LT_DP_LIST[].
        LT_DP_LIST-DOCID = LS_DP_HEADER-DOCID.
        LT_DP_LIST-DOCTYPE = LS_DP_HEADER-DOCTYPE.
        APPEND LT_DP_LIST.

        REFRESH LT_MSG[].
        CALL FUNCTION 'YBC_SWS_DP_APPROVED'
          EXPORTING
            AFTCS_VALIDATION = 'A'
            CUSTOM_FIELD4    = 'X'
          TABLES
            DP_LIST          = LT_DP_LIST
            RETURN           = LT_MSG.

        LOOP AT LT_MSG WHERE TYPE = 'E' OR TYPE = 'A' OR TYPE = 'X'.
          ES_MSG = LT_MSG.
          ES_MSG-TYPE = 'E'.
          EXIT.
        ENDLOOP.
        IF SY-SUBRC <> 0.
          ES_MSG-TYPE = 'S'.
          ES_MSG-MESSAGE = '发票单据已经审批完成'.
        ENDIF.

      ENDIF.

    WHEN OTHERS.

  ENDCASE.

ENDFUNCTION.
